/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package action.organization;

import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import myUtils.Constants;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;
import po.Organization;
import po.User;
import service.OrgService;

/**
 *
 * @author luyang
 */
public class GetOrgAction extends ActionSupport implements ServletRequestAware,SessionAware
{
    private HttpServletRequest request;
    private OrgService orgService;
    private Map session;

    @Override
    public String execute()
    {
        if(session.get("right")==null)
            session.put("right",String.valueOf(Constants.USER ));
        if(session.get("status")==null)
            session.put("status", String.valueOf(Constants.GUEST));

        String msg="";
        if(request.getParameter("id")==null)
            return ERROR;
        else
        {
            int id=Integer.parseInt(request.getParameter("id"));
            Organization org=orgService.getOrg(id);
            User user=orgService.getManagerOfOrg(id);
            if(org==null)
            {
                msg="null  organization!!!";
                request.setAttribute("msg", msg);
                return ERROR;
            }
            if(user==null)
            {
                msg="null user!!!";
                request.setAttribute("msg", msg);
                return ERROR;
            }

            request.setAttribute("org", org);
            request.setAttribute("user", user);
            System.out.println("org name : "+org.getName());
            System.out.println("user name : "+user.getId());
        }
        return SUCCESS;
    }

    public void setOrgService(OrgService orgService)
    {
        this.orgService=orgService;
    }

    public void setServletRequest(HttpServletRequest request)
    {
        this.request=request;
    }

    public void setSession(Map session)
    {
        this.session=session;
    }

}
